app = angular.module('myApp', ['ngRoute']);

app.config(function($routeProvider) {
	$routeProvider.when('/a', {
		templateUrl: 'a.html'
		//controller:"mk"
	}).when('/b', {
		templateUrl: 'b.html'
		//controller:"mk"
	})

})

app.controller('mk', ['$scope', '$http', function($scope, $http) {
	$http.get('./data/wm.json').then(function(res) {
		//(res)
		$scope.obj = res.data.info;

	})
	$scope.arr = [];
	//总数量
	$scope.sumsl = 0;
	$scope.zong = 0;
	$scope.dj = function($index) {
		//总数量
		$scope.sumsl++;

		$scope.zong += $scope.obj[$index].price;

		$scope.arr.push($scope.obj[$index]);

		$scope.obj[$index].fs++;
		//console.log($scope.arr)

		//i,j  都是下标
		for(var i = 0; i < $scope.arr.length; i++) {

			for(var j = i + 1; j < $scope.arr.length; j++) {

				if($scope.arr[i] == $scope.arr[j]) {
					$scope.arr.splice(i, 1);
					j--
				}
			}
		}
	}

	//清空

	$scope.qk = function() {
		$scope.sumsl = 0;
		zong = 0;
		angular.forEach($scope.obj, function(val, key) {
			//val   对象
			val.fs = 0
		})
		$scope.arr.length = [];
	}
}])